/*
 * Copyright© 2003-2019 浙江汇信科技有限公司, All Rights Reserved.
 */
package com.icinfo.cloud.provider.punish.common.csourcedocumentoperate.controller;

import com.icinfo.cloud.common.core.Validator.BaseGroup;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.punish.common.csourcedocumentoperate.dto.CSourceDocCommonHtmlRequest;
import com.icinfo.cloud.provider.punish.common.csourcedocumentoperate.dto.CSourceDocCommonOperateSaveDto;
import com.icinfo.cloud.provider.punish.common.csourcedocumentoperate.dto.CaseSourceTemplateCodeInfoDto;
import com.icinfo.cloud.provider.punish.common.csourcedocumentoperate.service.ICSourceDocCommonOperateService;
import com.icinfo.cloud.provider.punish.common.documentoperate.vo.DocumentCommonFormDataVo;
import com.icinfo.cloud.provider.punish.common.documentoperate.vo.DocumentCommonFormHtmlVo;
import com.icinfo.framework.common.web.Result;
import com.icinfo.framework.core.web.BaseController;
import com.icinfo.framework.tools.utils.MapUtils;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 案源文书公共操作控制类
 * @author liyafeng
 * @date 2022/8/16
 */
@RestController
@RefreshScope
@RequestMapping("/punish/csource/common")
@Slf4j
public class CSourceDocCommonOperateController extends BaseController {
    @Resource
    private ICSourceDocCommonOperateService icSourceDocCommonOperateService;

    /**
     * 描述：案源保存文书信息通用接口
     * @author liyafeng
     * @date 2022/8/16
      * @param saveDto
     * @return {@link Result< String>}
     */
    @PostMapping("/saveCSourceDocInfo")
    @ApiOperation(value = "【V1.0.0】描述：保存文书信息通用接口", httpMethod = "POST")
    public Result<Map<String, Object>> saveCSourceDocInfo(@RequestBody @Validated CSourceDocCommonOperateSaveDto saveDto) {
        Map<String, Object> resultMap = icSourceDocCommonOperateService.saveDocInfo(saveDto);
        String status = MapUtils.getString(resultMap, "success", "");
        if ("true".equals(status)) {
            return Result.success(Constant.STRING_SAVE_SUCCESS,resultMap);
        }
        return Result.error(Constant.STRING_SAVE_FAIL);
    }

    /**
     * 获取案源文书html公共方法
     * @author liyafeng
     * @date 2022/8/16
      * @param request
     * @return {@link Result< DocumentCommonFormHtmlVo>}
     */
    @PostMapping("/getCSourceDocBaseInfo")
    public Result<DocumentCommonFormHtmlVo> getDocHtml(@RequestBody @Validated(BaseGroup.Query.class) CSourceDocCommonHtmlRequest request) {
        DocumentCommonFormHtmlVo result = icSourceDocCommonOperateService.getDocumentFormHtml(request);
        return Result.success(Constant.STRING_GET_SUCCESS, result);
    }

    /**
     * 获取文书数据公共方法
     * @author liyafeng
     * @date 2022/8/16
      * @param request
     * @return {@link Result< DocumentCommonFormDataVo>}
     */
    @PostMapping("/getCSourceDocFormData")
    public Result<DocumentCommonFormDataVo> getDocFormData(@RequestBody @Validated(BaseGroup.Query.class) CSourceDocCommonHtmlRequest request) {
        DocumentCommonFormDataVo result = icSourceDocCommonOperateService.getCommonDocumentFormData(request);
        return Result.success(Constant.STRING_GET_SUCCESS, result);
    }


    /**
     * 描述：根据文书目录编码获取法人或个人文件模板code
     * @author liyafeng
     * @date 2022/8/16
      * @param dto
     * @return {@link Result< String>}
     */
    @PostMapping("/getTemplateCodeByDocumentCatalogCode")
    @ApiOperation(value = "【V1.3.2】描述：根据文书目录编码获取法人或个人文件模板code", httpMethod = "POST")
    public Result<String> getTemplateCodeByDocumentCatalogCode(@Validated @RequestBody CaseSourceTemplateCodeInfoDto dto) {
        String documentCatalogCode = dto.getDocumentCatalogCode();
        String caseSourceId = dto.getCaseSourceId();
        Map<String, Object> paramMap = dto.getParamMap();
        String templateCode = icSourceDocCommonOperateService.getTemplateCodeByDocumentCatalogCode(documentCatalogCode, caseSourceId, paramMap);
        return Result.success(Constant.STRING_GET_SUCCESS, templateCode);
    }

}
